import jwt

JWT_KEY = 'KDjcjSmjIeqEaTXP76qkw64SDMmmbxKi0WFxbYd+/Gc='
JWT_KEY_PF = 'qud15ncSPjpIeQbLgMJo4Vh9FwWWl0QAelGd7Uf5vac='
JWT_KEY_SP = 'S0RqY2pTbWpJZXFFYVRYUDc2cWt3NjRTRE1tbWJ4S2kwV0Z4YllkKy9HYz0='

s={'Authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJxeWFwaXRlc3QucWl5dWNsb3VkLmNvbS5jbiIsImlhdCI6MTcyNDM3OTU5NSwic3ViIjoie1wiY2xpZW50VHlwZVwiOjEzLFwiZGF0YVN0b3JhZ2VNb2RlbFwiOjIsXCJzdG9yZUlkXCI6MTUsXCJ0ZW5hbnRJZFwiOjE5NyxcInVzZXJJZFwiOjUzfSIsImV4cCI6MTcyNDk4NDU3NSwibmJmIjoxNzI0Mzc5NTk1fQ.u8vtY-O8uR4mXLpXEArhY1NpukMXKttUX5_U0BHnINA'}
token = s['Authorization'].split(' ')[1]

data={'iss': 'qyapi.qiyucloud.com.cn', 'iat': 1716964612, 'sub': '{"clientType":13,"dataStorageModel":2,"storeId":1,"tenantId":102503,"userId":41}', 'exp': 1717569592, 'nbf': 1716964612}
def decode_token(token):
    try:
        data = jwt.decode(token, JWT_KEY, algorithms=['HS256'])
    except:
        try:
            data = jwt.decode(token, JWT_KEY_PF, algorithms=['HS256'])
        except:
            try:
                data = jwt.decode(token, JWT_KEY_SP, algorithms=['HS256'])
            except:
                data = 'token解析失败!'

    print(data)
    return data

def encode_token(data):
    s=jwt.encode(data, JWT_KEY, algorithm='HS256')
    print(s)



data=decode_token(token)
# data = {'iss': 'qyapitest.qiyucloud.com.cn', 'iat': 1724379595, 'sub': '{"clientType":13,"dataStorageModel":2,"storeId":15,"tenantId":197,"userId":53}', 'exp': 1724984575, 'nbf': 1724379595}
encode_token(data)